/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package skaitiniai.metodai.perkeltiesMetodas;

/**
 * testuoja, ar matrica validi. 
 * @return -2 jei MATRICA VALIDI
 * @return -1 jei niekur netenkinama griezta nelygybe
 * @return 0...N-1 eilutes, kurioje netenkinama negriezta nelygybe, indeksas
 *
 * 
 */
public class MatricosValidatorius {
    public static final int VALIDI = -2;
    public static final int NETENKINAMA_GRIEZTA = -1;
    
    private static MatricosValidatorius instance = null;
 
    boolean griezta;
    
    private MatricosValidatorius(){};
    
    public static MatricosValidatorius getInstance(){
        if (instance == null){
            instance = new MatricosValidatorius();
        }
        return instance;
    }
    
    public int patikrintiMatrica (TriistrizaineMatrica matrica){
        double[] a = matrica.getA();
        double[] b = matrica.getB();
        double[] c = matrica.getC();
        griezta = Boolean.valueOf(false);
        for (int i = 0; i < b.length; i ++){
            if (Math.abs(a[i]) + Math.abs(c[i]) > Math.abs(b[i])){
                return i; //jei kazkurioje eiluteje netenkinama negriezta, iskart grazinam eilutes indeksa
            }
            if (Math.abs(a[i]) + Math.abs(c[i]) < Math.abs(b[i])){
                griezta = Boolean.valueOf(true); // jei aptinkam, kad kazkur tenkinama griezta, pazymim
            }
        }
        
        if (griezta){ //jei nenuluzo del negrieztos anksciau, ir atejo iki cia, patikrinam ar buv pazymeta griezta
            return VALIDI;
        }else{
            return NETENKINAMA_GRIEZTA;
        }
        
    }
    
}
